import { createSSRApp } from 'vue'
import App from './App.vue'
import store from './store'
import { routeInterceptor, requestInterceptor, prototypeInterceptor } from './interceptors'
import 'virtual:uno.css'
import '@/style/index.scss'
import customHeader from './components/customHeader/index.vue'
import customExpect from './components/customExpect/index.vue'
import customTabbar from './components/customTabbar/index.vue'
// console.log(import.meta.env, '环境变量')

export function createApp() {
  const app = createSSRApp(App)

  // 全局变量声明
  // 图片CDN
  app.config.globalProperties.staticUrl = (img) => {
    if (import.meta.env.VITE_SHOW_CDN === '2') {
      return `https://yl-dev-goods.oss-cn-chengdu.aliyuncs.com/WEB/yl-uniapp-image${img}`
    } else {
      return `${img}`
    }
  }

  // 跳转路由
  app.config.globalProperties.routerTo = (data) => {
    uni.navigateTo({
      url: data.path,
    })
  }

  // 全局组件声明
  // 顶部菜单
  app.component('customHeader', customHeader)
  // 缺省页 敬请期待
  app.component('customExpect', customExpect)
  // 底部菜单
  app.component('customTabbar', customTabbar)

  app.use(store)
  app.use(routeInterceptor)
  app.use(requestInterceptor)
  app.use(prototypeInterceptor)
  return {
    app,
  }
}
